package me.wangxuan.pat.view;

import java.awt.Component;

import javax.swing.JButton;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;

public class ButtonRenderer implements TableCellRenderer {
	private JButton button;

    public ButtonRenderer() {
        button = new JButton();
//        button.setPreferredSize(new Dimension(5, 5)); // 设置按钮的首选大小
        button.setOpaque(true);
        button.setFocusPainted(false); // 可选，如果你不想显示按钮的边框
    }

    @Override
    public Component getTableCellRendererComponent(JTable table, Object value,
                                                boolean isSelected, boolean hasFocus,
                                                int row, int column) {
        if (value instanceof String) {
            button.setText((String) value);
            button.setBackground(isSelected ? table.getSelectionBackground() : table.getBackground());
            button.setForeground(isSelected ? table.getSelectionForeground() : table.getForeground());
        }
        // 设置按钮的大小
//        button.setPreferredSize(new Dimension(23, 23)); // 宽度80像素，高度23像素
        return button;
    }
}
